#!/usr/bin/perl
use strict;                # Hook script to remove ^M characters from files to be committed
use warnings;  

my @extensions = (".jar", ".zip", ".gz", ".tar", ".exe", ".dll", ".so");

################# Do not modify after this line. ######################

my $repo = shift;          # Location of the repository and transaction ID is being passed from pre-commit hook script
my $txn = shift;

sub get_extension{ 
    my $file = shift;
    my ($extension) = $file =~ /(\.[^.]+)$/;
    return $extension;
}  

sub openfile{
    my $currentfile = shift;
    open FILE, "$currentfile" or die $!; 
    open TMP, ">tempfile" or die $!;
      while(<FILE>)
      { 
        my($currentline) = $_;
        chomp($currentline);
        $currentline =~ s/\r//g;
        print TMP "$currentline\n";
      }
    close TMP;
    close FILE;
    rename("tempfile","$currentfile");
}   

sub main{
  my @path = `svnlook changed -t $txn $repo`;
  foreach my $l(@path)
  {   
      my @store = split('   ',$l);
      my $currentfile = $store[1];
      chomp($currentfile); 
      my $ext;   
      $ext = get_extension($currentfile);  
        if ($ext ~~ @extensions){next;}
        if ($currentfile eq '.'){ next;}
      openfile($currentfile);
  } 
}

main();

